package com.hjt.gulimall.product.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

/**
 * @author:97007
 * @date:2021/9/23 20:25
 */
@Configuration
public class MyRedissionConfig {


    @Value("${spring.redis.password}")
    private String redisPassword;

        /**
         * 所有对redisson的使用，通过redissonClient完成
         * @return
         * @throws IOException
         */
        @Bean(destroyMethod="shutdown")
        RedissonClient redisson() throws IOException {
            // 单节点模式
            // 1.创建config
            // Redis url should start with redis:// or rediss:// (for SSL connection)
            Config config = new Config();
            config.useSingleServer().setAddress("redis://114.132.223.218:6379");
            config.useSingleServer().setPassword(redisPassword);
            // 2.根据config创建redisson实例
            return  Redisson.create(config);
        }

}
